package practise.mulitThreads.ConcurrentInPractice.secondTime;

import practise.mulitThreads.EventSystem.Server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Richard on 7/28/2014.
 */
public class RequestHandler {
    private  int connectionLimitions =0;
    public RequestHandler(int maxConnection){
        connectionLimitions = maxConnection;
    }
    public void receiver() throws IOException {
        ServerSocket serverSocket = new ServerSocket(80);
        ExecutorService executorService = getExecutor();
        while(!Thread.currentThread().isInterrupted()) {
            Socket socket = serverSocket.accept();
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    handleRequest(socket);
                }
            });

        }
    }

    public void handleRequest(Socket connection){

    }

    public ExecutorService getExecutor(){
        return Executors.newFixedThreadPool(connectionLimitions);
    }
}
